//
//  E7Logic.h
//  EndlessBattle
//
//  Created by cc on 12-3-17.
//  Copyright (c) 2012年 PalmGame. All rights reserved.
//

#ifndef EndlessBattle_E7Logic_h
#define EndlessBattle_E7Logic_h

#include "E7GameDefine.h"

#include "E7Map.h"
#include "E7Unit.h"
#include "E7Town.h"
#include "E7Country.h"

#include "E7Robot.h"
#include "E7Rule.h"

class CE7Logic
{
public:
    CE7Logic() ;
    ~CE7Logic() ;

    void     CreateMap() ;
    void     CreateStartMap() ;

    bool     InitLogicData() ;

    CE7Map*  ActiveMap()    { return m_pActiveMap ; }
    CE7Rule* GetRule()      { return m_pRule ; }
    int      GetMapID()     { return m_nMapIndex ; }
    bool     IsActived()    { return m_bIsActived ; }
    bool     IsUserTurn()   { return (0 == m_nTurnID) ; }
    int      GetTurnID()    { return m_nTurnID ; }
    int      GetTurnCount() { return m_nTurnCount ; }
    int      GetNewUnitID() { return ++m_nUnitSize ; }
    int      GetNewTownID() { return ++m_nTownSize ; }
    bool     IsGameEnd()    { return m_bIsGameEnd ; }

    void     NextTurn()     { ++m_nTurnID ; }
    void     SetTurnID(int turnid) { m_nTurnID = turnid ; }
    void     SetGameEnd()   { m_bIsGameEnd = true ; }

    void     SetStageMap(int nID) { m_nMapIndex = nID ; }
    int      GetStageMap() { return m_nMapIndex ; }

    void     SetGameMode(int flag) { m_nGameMode = flag ; }
    int      GetGameMode() { return m_nGameMode ; }

    void     SetCustomMapID(int mapid) { m_nCustomMapID = mapid ; }
    int      GetCustomMapID() { return m_nCustomMapID ; }

    int      GetStageCount() { return m_nStageCount ; }

    void     SetFirstGame() { m_bIsFirst = true ; }
    bool     IsFirstGame() { return m_bIsFirst ; }

    bool     Loop() ;

public:
    bool AddUnitInfo(CE7Unit* pUnit) ;
    bool AddTownInfo(CE7Town* pTown) ;

public:
    CE7Unit*    GetSelectUnitInfo(int nID) ;
    bool        DelSelectUnitInfo(int nID) ;

    CE7Town*    GetSelectTownInfo(int nID) ;
    bool        DelSelectTownInfo(int nID) ;

    CE7Country* GetSelectCountryInfo(int nID) ;
//    CE7Map*     GetSelectMapInfo(int nID) ;
    CE7Robot*   GetSelectRobotInfo(int nID) ;

public:
//    MAP_INFO_LIST        m_listMap ;
    UNIT_INFO_LIST       m_listUnit ;
    TOWN_INFO_LIST       m_listTown ;
    COUNTRY_INFO_LIST    m_listCountry ;
    ROBOT_INFO_LIST      m_listRobot ;

private:
    void FindAllWithCell(CE7Cell* pStart) ;
    void SetCellTownID(int countryid, CELL_ID_LIST tlist) ;

private:

    bool                 m_bIsActived ;
    CE7Map*              m_pActiveMap ;
    CE7Rule*             m_pRule ;

    int                  m_nTurnID ;// robot's id.
    int                  m_nTurnCount ;
    int                  m_nTurnMax ;

//    int                  m_nCountrySize ;
    int                  m_nTownSize ;
    int                  m_nUnitSize ;

    bool                 m_bIsGameEnd ;

private:
    int                  m_nStageCount ;
    int*                 m_pStageData ;

    int                  m_nGameMode ; // 0 - stage mode, 1 - custom mode.
    int                  m_nMapIndex ;
    int                  m_nCustomMapID ;
    bool                 m_bIsFirst ;

    // render info.
public:
    bool s_bIsBalance ;

    CE7Cell* s_pSelect ;
    bool s_bIsRedraw ;
    
    bool s_bIsUpdateInfo ;
    eUnitValue s_eCreateUV ;
    eUnitValue s_eSelectUV ;
    int s_eSelUnitID ;
    int s_nGold ;
    int s_nInGold ;
    int s_nSoldierCount ;
    int s_nSoldierSub ;
    int s_nTowerCount ;
    int s_nTowerSub ;

    bool s_bIsRestart ;

    // debug.
public:
    int create_unit_count ;
    int delete_unit_count ;
    int create_town_count ;
    int delete_town_count ;
} ;

extern CE7Logic* s_pLogic ;

#endif















